package com.example.finalwork.Day;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.example.finalwork.DAO.IncomeDAO;
import com.example.finalwork.DAO.PayDAO;
import com.example.finalwork.Entity.Income;
import com.example.finalwork.Entity.Pay;
import com.example.finalwork.LoginActivity;
import com.example.finalwork.MainActivity;
import com.example.finalwork.R;
import com.example.finalwork.lmpl.IncomeDAOlmpl;
import com.example.finalwork.lmpl.PayDAOlmpl;

import java.util.List;

public class DayActivity extends AppCompatActivity implements View.OnClickListener{
    private LinearLayout ll_content3;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_day);
        int count=0;
        findViewById(R.id.button5).setOnClickListener(this);

        ll_content3 = findViewById(R.id.ll_content3);

        IncomeDAO incomeDAO5 = new IncomeDAOlmpl(this);
        List<Income> incomes5 = incomeDAO5.GetAllIncomeybydate();
        for(int i = 0 ; i < incomes5.size() ; i++)
        {
            Income income5 = incomes5.get(i);
            if(LoginActivity.data.equals(income5.getIn_User()))
            {
                count = count + 1 ;
                TextView textView3 = new TextView(this);
                textView3.setText("\t\t\t\t\t\t"+String.valueOf(count) + "\t\t\t\t\t\t\t\t\t\t\t\t"  + income5.getIn_Date() + "\t\t\t\t\t\t\t\t\t" + "收入" + "\t\t\t\t\t\t\t\t\t" + income5.getIn_Amount());
                textView3.setTextSize(18);
                ll_content3.addView(textView3);
            }
        }
        PayDAO payDAO5 = new PayDAOlmpl(this);
        List<Pay> pays5 = payDAO5.GetAllPaybydate();
        for(int i = 0 ; i < pays5.size() ; i++)
        {
            Pay pay5 = pays5.get(i);
            if(pay5.getPay_User().equals(LoginActivity.data))
            {
                count = count + 1;
                TextView textView2 = new TextView(this);
                textView2.setText("\t\t\t\t\t\t"+String.valueOf(count) + "\t\t\t\t\t\t\t\t\t\t\t\t"  + pay5.getPay_Date() + "\t\t\t\t\t\t\t\t\t" + "支出" + "\t\t\t\t\t\t\t\t\t" + pay5.getPay_Amount());
                textView2.setTextSize(18);
                ll_content3.addView(textView2);
            }
        }

        setTitle("日账单功能");
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.button5:
                Toast.makeText(this,"返回上一级",Toast.LENGTH_SHORT).show();
                startActivity(new Intent(this, MainActivity.class));
                break;
        }
    }
}
